package com.example.forum.dao;

import com.example.forum.domain.Comment;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import java.util.List;

@Mapper
@Repository
public interface CommentDao {
    //根据评论的类型查询评论
    @Select("select * from comment where status=0 and entity_type=#{entityType} and entity_id=#{entityId} order by create_time asc limit #{start},#{size}")
    public List<Comment> findByEntityType(@Param("entityType") int entityType,@Param("entityId") int entityId,
                                          @Param("start") int start,@Param("size") int size);

    //根据评论类型查询评论的条数
    @Select("select count(*) from comment where status=0 and entity_type=#{entityType} and entity_id=#{entityId}")
    public Integer findByEntityTypeCount(@Param("entityType") int entityType,@Param("entityId") int entityId);

    //增加评论
    @Insert("insert into comment values(null,#{userId},#{entityType},#{entityId},#{targetId},#{content},#{status},#{createTime})")
    public void addComment(Comment comment);
}
